(function () {
  const elevator = document.querySelector('.xtx-elevator')
  const backTop = document.querySelector('#backTop')
  window.addEventListener('scroll', function () {
    const n = document.documentElement.scrollTop
    if (n > 300) elevator.style.opacity = 1
    else elevator.style.opacity = 0
  })
  backTop.addEventListener('click', function () {
    window.scrollTo(0, 0)
  })
})();

   (function () {
    const elevator = document.querySelector('.xtx-elevator-list')
    elevator.addEventListener('click', function (e) {
      if (e.target.tagName === 'A') {
        const name = e.target.dataset.name
        const target = document.querySelector(`.xtx_goods_${name} `)
        window.scrollTo(0, target.offsetTop)
      }
    })
})();
  
    (function () {
      const arr = ['new', 'popular', 'brand', 'topic']
      const elevator = document.querySelector('.xtx-elevator-list')
      for (let i = 0; i < arr.length; i++){
        arr[i]=document.querySelector(`.xtx_goods_${arr[i]} `).offsetTop
      }
      window.addEventListener('scroll', function () {
        const n = document.documentElement.scrollTop
        elevator.querySelector('li a.active')&&elevator.querySelector('li a.active').classList.remove('active')
        if ( n >=arr[0]&&n<arr[1]) {
          elevator.querySelector('li:nth-child(1) a').className='active'
        }else if ( n >= arr[1]&&n<arr[2]) {
          elevator.querySelector('li:nth-child(2) a').className='active'
        }else if ( n >= arr[2]&&n<arr[3]) {
          elevator.querySelector('li:nth-child(3) a').className='active'
        }else if ( n >= arr[3]) {
          elevator.querySelector('li:nth-child(4) a').className='active'
        }
      })
    })();
